Node Patterns - Networking by Teixeira Pedro

Node Patterns - Networking by Teixeira Pedro

Author:Teixeira, Pedro [Teixeira, Pedro]
Language: eng
Format: epub
Published: 2015-04-07T18:30:00+00:00


Once the server is back up, the client should reconnect successfully and resume operations:

connected DOOR OPEN FOR MORE THAN 1 SECOND, GO CLOSE IT!!! closed now DOOR OPEN FOR MORE THAN 1 SECOND, GO CLOSE IT!!! disconnected disconnected disconnected disconnected disconnected disconnected connected DOOR OPEN FOR MORE THAN 1 SECOND, GO CLOSE IT!!! closed now DOOR OPEN FOR MORE THAN 1 SECOND, GO CLOSE IT!!!

9. Multiplexing Streams

Let’s say now that your refrigerator door sensor server has been proved a success, and that you want to extend it. For instance, you would like to sense the refrigerator temperature and make that data available to the clients connecting to the server.

But there’s a problem: you will need to add more event types and also change the ones that exist: open and close would have to be changed to door open and door close and you will also have to add temperature reading or something similar.

These events should be separated, i.e. transported in different streams, to make the server and client implementations easier and more adaptable to change. We could create different sub-streams on the server -> client stream, one for each device: one for the door sensor, another for the thermometer, and yet another should you choose to add yet another sensor to the refrigerator.

Fortunately this can be easily accomplished by using the mux-demux NPM package: it lets us:

on the server side, multiplex several streams into one stream;

on the client side, do the inverse: demultiplex that stream into separate streams to treat them individually



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.